home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Michael D. Crawford↵ / Word Services SDK 1.0.5 / Writeswell Jr. Source / InitWWJr.c < prev    next >
Text File  |  1992-10-23  |  3KB  |  121 lines

  1. /* InitWWJr.c
  2.  * Initialization code for Writeswell Jr.
  3.  *
  4.  * ©1992 Working Software, Inc.
  5.  * This source code is copyrighted.  Permission is granted to use the Word Services
  6.  * portion of the Writeswell Jr. source code in your own programs, but you 
  7.  * may not distribute the Writeswell Jr. word-processor code as a 
  8.  * commercial product.  If you modify the code, please do not call it 
  9.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  10.  * program and don’t have to deal with a number of different versions with 
  11.  * who-knows-what going on in the code.
  12.  * 
  13.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  14. */
  15.  
  16. #include <EPPC.h>
  17. #include <AppleEvents.h>
  18. #include "GenHandlers.h"
  19. #include "AppEvents.h"
  20. #include "InitMenu.h"
  21. #include "Gripe.h"
  22. #include "AEObj.h"
  23. #include "MyFiles.h"
  24. #include "InitWWJr.h"
  25.  
  26. OSErr CheckApplParams( SFReply *replyPtr );
  27.  
  28. OSErr InitForSystem7( void )
  29. {
  30.     OSErr    err;
  31.  
  32.     PutUpSys7Menus();
  33.  
  34.     if ( err = InitReqHandlers() )
  35.         return err;
  36.  
  37.     if ( err = InitGenericHandlers() )
  38.         return err;
  39.  
  40.     if ( err = InitAEObjStuff() )
  41.         return err;
  42.     
  43.     return noErr;
  44. }
  45.  
  46. OSErr InitForSystem6( void )
  47. {
  48.     OSErr    err;
  49.     SFReply    reply;
  50.  
  51.     PutUpSys6Menus();
  52.     
  53.     CheckApplParams( &reply );
  54.  
  55.     if ( reply.good ){
  56.         err = MyOpenSfFile( &reply );
  57.     }else{
  58.         err = MakeNewWindow();
  59.     }
  60.     
  61.     return err;
  62. }
  63.  
  64. OSErr CheckApplParams( SFReply *replyPtr )
  65. {
  66.     short            message;
  67.     short            count;
  68.     short            i;
  69.     AppFile            file;
  70.     short            vRef;
  71.     ParamBlockRec    fPB;
  72.     OSErr            err;
  73.  
  74.     replyPtr->good = false;
  75.  
  76.     CountAppFiles(&message,&count);
  77.     if (!count)
  78.         return noErr;
  79.  
  80.     err = GetVol(0L,&vRef);
  81.     if ( err ){
  82.         Gripe( "\pGetVol failed" );
  83.         return err;
  84.     }
  85.  
  86.  
  87.     /* Loop through all the files that were selected on the desktop,
  88.        skipping all that don't have a type of 'TEXT' */
  89.     for (i = 1; i <= count; i++)
  90.     {
  91.         GetAppFiles(i, &file);
  92.  
  93.         /* If it’s not a file type we can open, skip it */
  94.         if (file.fType == 'TEXT' )
  95.         {            
  96.             fPB.fileParam.ioCompletion = (ProcPtr)NULL;
  97.             fPB.fileParam.ioNamePtr = (StringPtr)NULL;
  98.             fPB.fileParam.ioVRefNum = file.vRefNum;
  99.             
  100.             err = PBSetVol( &fPB, false );
  101.             if ( err ){
  102.                 Gripe( "\pPBSetVol failed in MyOpenSpecFile" );
  103.                 return err;
  104.             }
  105.  
  106.             replyPtr->vRefNum = file.vRefNum;
  107.             replyPtr->fType = file.fType;
  108.             replyPtr->version = file.versNum;
  109.             BlockMove( file.fName, replyPtr->fName, (file.fName)[0] + 1 );
  110.             replyPtr->copy = false;
  111.             replyPtr->good = true;
  112.             
  113.             return noErr;
  114.         }
  115.  
  116.         ClrAppFiles(i);
  117.     }
  118.  
  119.     return noErr;
  120. }
  121.